//
//  TTMineViewController.m
//  TaoTuo
//
//  Created by admin on 2019/8/15.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTMineViewController.h"
#import "TTMineViewCell.h"
#import "TTMineViewModel.h"
#import "TTMineHeaderView.h"
#import "TTMypageCountModel.h"
#import "TTSetViewController.h"
#import "TTMainEventHandle.h"
#import "TTMyOrderViewController.h"
#import "TTDianpuManagerViewController.h"
#import "TTOpenShopViewController.h"
#import "TTOpenPlusViewCell.h"
#import "TTMineBigPosterViewCell.h"
#import "TTPostersViewController.h"

#import "TTUpdateModel.h"



#import "TTQuickEstimateViewController.h"

static NSString *openPlusTitle = @"开通商城";
static NSString *myOrderTitle = @"我的订单";
static NSString *myDianpuManagerTitle = @"店铺管理";
static NSString *latestPosterTitle = @"店铺海报";
static NSString *myServiceTitle = @"我的服务";

static NSString *openPlusCellID = @"plus_cell_id";
static NSString *cellID = @"mine_cell_id";
static NSString *posterCellID = @"mine_poster_cell_id";


@interface TTMineViewController ()<UITableViewDelegate, UITableViewDataSource, TTMineViewCellDelegate>
{
    CGFloat topImageViewH;
    
}

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) TTMineHeaderView *headerView;
@property (nonatomic, strong) UIImageView *headerBGImageView;
@property (nonatomic, strong) UIImage *shadowImage;
@property (nonatomic, strong) UIActivityIndicatorView *activityView;
@property (nonatomic, strong) UIView *navAlphaView;
@property (nonatomic, strong) UIView *navBarView;
@property (nonatomic, strong) NSArray *notNeedLoginTitleArray;  // 不需要登录就能进去的
///海报urlstring
@property (nonatomic, strong) NSArray *posterArray;
///保存海报的key
@property (nonatomic, copy) NSString *posterUseKey;

@end

@implementation TTMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    topImageViewH = 160 * kScale + StatusBarAndNavBar_Height;
    self.title = @"我的";
    self.view.backgroundColor = kSeparatorColor;
    self.fd_prefersNavigationBarHidden = YES;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getNetworkDatas) name:@"refreshPageCountNotify" object:nil];
    
    
    // 点击不用登录就能进去的
    self.notNeedLoginTitleArray = @[@"实时金价", @"公告", @"帮助中心"];
    
    [self setupSubviews];
    [self setupDatasWithCachePoster:[self getCachePosterDatas]];
    
    [self getNetworkDatas];
    
    // 登录或退出
    @weakify(self)
    [[TTLoginSingle sharedSingle].loginSubject subscribeNext:^(id  _Nullable x) {
        @strongify(self)
        [self getNetworkDatas];

    }];
    
    ///修改成功用户信息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(modifyUserInfoSuccessNotify) name:@"modifyUserInfoSuccess_key" object:nil];
    
}

///修改成功用户信息
- (void)modifyUserInfoSuccessNotify
{
    [self.headerView setUserData];
}

// 设置
- (void)clickSetBtnAction
{
    TTSetViewController *setVC = [[TTSetViewController alloc] init];
    [self.navigationController pushViewController:setVC animated:YES];
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat offsetY = scrollView.contentOffset.y;
    if (offsetY <= 0) {
        CGFloat s = (300 - offsetY) / 300.0;
        self.headerBGImageView.transform = CGAffineTransformMakeScale(1, s);
    }
    CGFloat alpha = offsetY / 100.0;
    self.navAlphaView.alpha = alpha;
    
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
    CGFloat offsetY = scrollView.contentOffset.y + kStatusBarHeight;
    if (offsetY <= -60) {
        if (!self.activityView.isAnimating) {
            [self.activityView startAnimating];
            
            [self getNetworkDatas];
        }
    }
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TTMineViewModel *model = self.dataArray[indexPath.section];
    if ([model.sectionTitle isEqualToString:openPlusTitle]) {
        TTOpenPlusViewCell *cell = [tableView dequeueReusableCellWithIdentifier:openPlusCellID];
        return cell;
    } else if ([model.sectionTitle isEqualToString:latestPosterTitle]) {
        TTMineBigPosterViewCell *cell = [tableView dequeueReusableCellWithIdentifier:posterCellID];
        cell.model = model;
        return cell;
    } else {
        TTMineViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        cell.model = model;
        cell.delegate = self;
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TTMineViewModel *model = self.dataArray[indexPath.section];
    if ([model.sectionTitle isEqualToString:openPlusTitle]) {
        return 70;
    } else if ([model.sectionTitle isEqualToString:latestPosterTitle]) {
        return 143;
    }
    
    NSInteger count = model.itemModelArray.count;
    NSInteger row = ceil(count / 5.0);
    return row * 60 + 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    TTMineViewModel *model = self.dataArray[indexPath.section];
    if ([model.sectionTitle isEqualToString:openPlusTitle]) {
        // 开通商城
        if (![TTLoginSingle sharedSingle].isLogin) {
            [self presentLoginViewController];
            return;
        }
        TTOpenShopViewController *openVC = [[TTOpenShopViewController alloc] initWithRenewal:NO];
        [self.navigationController pushViewController:openVC animated:YES];
    }
}

//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
//{
//    if (section == 0) {
//        return 0.1;
//    }
//    return 10;
//}
//
//- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
//{
//    if (section == 0) {
//        return [UIView new];
//    }
//    return [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
//}

#pragma mark - TTMineViewCellDelegate
- (void)mineViewCell:(TTMineViewCell *)cell selectItem:(TTMineItemModel *)itemModel index:(NSInteger)index
{
    NSLog(@"---> %@, %ld", itemModel.title, index);
    TTLoginSingle *single = [TTLoginSingle sharedSingle];
    if (!single.isLogin && ![self.notNeedLoginTitleArray containsObject:itemModel.title]) {
        [self presentLoginViewController];
        return;
    }
    
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    TTMineViewModel *model = self.dataArray[indexPath.section];
    
    if ([model.sectionTitle isEqualToString:myOrderTitle]) {
        // 订单
        TTMyOrderViewController *orderVC = [[TTMyOrderViewController alloc] init];
        orderVC.defaultIndex = index+1;
        [self.navigationController pushViewController:orderVC animated:YES];
    } else if ([model.sectionTitle isEqualToString:myDianpuManagerTitle]) {
        // 店铺管理
        [self presentDianpuViewController];
    }  else if ([model.sectionTitle isEqualToString:myServiceTitle]) {
        // 服务
        [TTMainEventHandle handleSelectorWithString:itemModel.imageName viewController:self];   
    }
}

/// 店铺管理
- (void)presentDianpuViewController
{
    TTDianpuManagerViewController *dianpuVC = [[TTDianpuManagerViewController alloc] init];
    LLNavigationViewController *nav = [[LLNavigationViewController alloc] initWithRootViewController:dianpuVC];
    nav.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:nav animated:YES completion:nil];
}

///获取数据
- (void)getNetworkDatas
{
    co_launch(^{
        
        await([self getUserData]);
        await([self getVipInfo]);
        self.posterArray = await([self getLasterPosterInfo]);
        
        [self.headerView setUserData];
        [self setupDatasWithCachePoster:nil];
        
        TTMypageCountModel *model = await([self getPageCountData]);
        if (model) {
            NSArray *ddArray = [NSArray arrayWithObjects:model.OdWaitConfirm, model.OdDoint, model.OdWaitSend, model.OdSend, model.OdWaitPay, nil];
            [self refreshPageViewWithDingdanCountArray:ddArray couponCount:model.CouponNoUse dpWaitItemCount:model.OdPlusShopWaitOrder];
        }
        
    });
}

/// 获取用户数据
- (COPromise *)getUserData
{
    COPromise *promise = [COPromise promise];
    [[LLNetworkManagerTool sharedManager] requestMethod:GET urlString:updateApp_api parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 获取手机当前版本号 如：1.05 * 1000，不要使用1.0.5这样的，计算会出错
        CGFloat currentVersionCode = [kCurrentVersion floatValue] * 1000;
        TTUpdateModel *updateModel = [TTUpdateModel modelWithJSON:responseObject];
        if (currentVersionCode <= updateModel.LoginVersionCode) {
            // 店铺可以显示
            [TTLoginSingle sharedSingle].mineDianpuShow = YES;
        }
        
        [promise fulfill:updateModel];
        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nullable error) {
        [promise fulfill:nil];
        
    } showLoadingInView:nil];
    
    return promise;
}

- (COPromise *)getVipInfo
{
    COPromise *promise = [COPromise promise];
    [TTCommonNetData getVipLevelSuccess:^(TTUserModel * _Nonnull userModel) {
        [promise fulfill:userModel];
    } failure:^{
        [promise fulfill:nil];
    }];
    return promise;
}

// 获取数字
- (COPromise *)getPageCountData
{
    COPromise *promise = [COPromise promise];
    
    if (![TTLoginSingle sharedSingle].isLogin) {
        // 未登录，设为0
        [self refreshPageViewWithDingdanCountArray:@[@"0", @"0", @"0", @"0"] couponCount:@"0" dpWaitItemCount:@"0"];
        [self.activityView stopAnimating];
        [promise fulfill:nil];
        return promise;
    }
    
    @weakify(self)
    [[LLNetworkManagerTool sharedManager] requestMethod:GET urlString:myPageCount_api parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        @strongify(self)
        [self.activityView stopAnimating];
        
        TTMypageCountModel *model = [TTMypageCountModel modelWithJSON:responseObject];
        [promise fulfill:model];
        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nullable error) {
        @strongify(self)
        [self.activityView stopAnimating];
        [promise fulfill:nil];
    } showLoadingInView:nil];
    
    return promise;
    
}

///获取海报信息
- (COPromise *)getLasterPosterInfo
{
    COPromise *promise = [COPromise promise];
    //只有商家才有海报
    if ([TTLoginSingle sharedSingle].userModel.VipLevel == 0) {
        [promise fulfill:nil];
        return promise;
    }
    @weakify(self)
    [[LLNetworkManagerTool sharedManager] requestMethod:GET urlString:getShopPoster_api parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        @strongify(self)
        NSArray *arr = responseObject;
        if (arr.count > 8) {
            arr = [arr subarrayWithRange:NSMakeRange(0, 8)];
        }
        ///保存海报
        [self savePosterDatas:arr];
        [promise fulfill:arr];
        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nullable error) {
        [promise fulfill:nil];
    } showLoadingInView:nil];
    
    return promise;
}

- (void)refreshPageViewWithDingdanCountArray:(NSArray *)ddArray couponCount:(NSString *)couponCount dpWaitItemCount:(NSString *)dpWaitItemCount
{
    NSInteger index = [self getDingdanModelIndex];
    
    // 2. 店铺管理代下单
    if ([TTLoginSingle sharedSingle].userModel.VipLevel == 1) {
        TTMineViewModel *dpViewModel = self.dataArray[index];
        TTMineItemModel *dpItemModel = dpViewModel.itemModelArray.firstObject;
        dpItemModel.count = dpWaitItemCount.intValue;
    }
    
//    // 1. 订单
//    TTMineViewModel *ddViewModel = self.dataArray.lastObject;
//    for (int i = 0; i < ddArray.count; i++) {
//        TTMineItemModel *itemModel = ddViewModel.itemModelArray[i];
//        itemModel.count = [ddArray[i] intValue];
//    }
    
    // 3. 服务中的优惠券
    if (self.dataArray.count > index + 2) {
        TTMineViewModel *fwViewModel = self.dataArray[index + 2];
        TTMineItemModel *fwItemModel = fwViewModel.itemModelArray.firstObject;
        fwItemModel.count = couponCount.intValue;
    }
    
    [self.tableView reloadData];
}

/// 获取店铺的index
- (NSInteger)getDingdanModelIndex
{
    if (![TTLoginSingle sharedSingle].mineDianpuShow) {
        //如果不显示店铺信息
        return 0;
    }
    int index = [TTLoginSingle sharedSingle].userModel.VipLevel == 0 ? 1 : 0;
    return index;
}

//// 查看所有订单
//- (void)lookAllOrder
//{
//    TTMyOrderViewController *orderVC = [[TTMyOrderViewController alloc] init];
//    [self.navigationController pushViewController:orderVC animated:YES];
//}

// 访问我的商城
- (void)accessMyMallAction
{
    NSString *domainStr = [TTLoginSingle sharedSingle].userModel.ShopDomainName;
    if (domainStr.length > 0) {
        domainStr = [domainStr urlEncode];
    }
    NSURL *url = [NSURL URLWithString:domainStr];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
    }
}

//分享海报
- (void)gotoSharePosterAction
{
    TTPostersViewController *posterVC = [[TTPostersViewController alloc] init];
    [self.navigationController pushViewController:posterVC animated:YES];
}

- (void)setupDatasWithCachePoster:(NSArray *)cachePosterArray
{
    [self.dataArray removeAllObjects];
    
    
    if ([TTLoginSingle sharedSingle].userModel.VipLevel == 0) {
        //普通会员，不是商家，并且能显示
        if ([TTLoginSingle sharedSingle].mineDianpuShow) {
            TTMineViewModel *model0 = [TTMineViewModel setModelWithSectionTitle:openPlusTitle itemArray:@[]];
            [self.dataArray insertObject:model0 atIndex:0];
        }
    } else {
        // 商家
        NSArray *dpItemImages = @[@"daixiadan", @"dingdan", @"shangpinguanli", @"beilv", @"shangchengshezhi"];
        NSArray *dpItemTitles = @[@"待下单", @"全部订单", @"商品管理", @"倍率设置", @"商城管理"];
        NSMutableArray *dianpuArray = [NSMutableArray array];
        for (int i = 0; i < dpItemImages.count; i++) {
            TTMineItemModel *model = [TTMineItemModel setImageName:dpItemImages[i] title:dpItemTitles[i]];
            [dianpuArray addObject:model];
        }
        TTMineViewModel *model3 = [TTMineViewModel setModelWithSectionTitle:myDianpuManagerTitle btnTitle:@"访问我的商城" target:self action:@selector(accessMyMallAction) itemArray:dianpuArray];
        model3.corner = UIRectCornerTopLeft | UIRectCornerTopRight;
        [self.dataArray addObject:model3];
        
        // 海报
        if (cachePosterArray.count > 0) {
            self.posterArray = cachePosterArray;
        }
        if (self.posterArray) {
            NSMutableArray *posterArr = [NSMutableArray array];
            for (NSString *urlString in self.posterArray) {
                TTMineItemModel *model = [TTMineItemModel setImageName:urlString title:@""];
                [posterArr addObject:model];
            }
            TTMineViewModel *model4 = [TTMineViewModel setModelWithSectionTitle:latestPosterTitle btnTitle:@"" target:self action:@selector(gotoSharePosterAction) itemArray:posterArr];
            model4.corner = UIRectCornerBottomLeft | UIRectCornerBottomRight;
            [self.dataArray addObject:model4];
        }
        
    }
    
    //    NSArray *fwItemImages = @[@"youhuiquan", @"shoucang", @"zuji", @"dizhi", @"hangqing", @"jiangli", @"yaoqing", @"notification", @"jisuanqi", @"bangzhu"];
    //    NSArray *fwItemTitles = @[@"优惠券", @"收藏", @"足迹", @"管理地址", @"实时金价", @"新手奖励", @"邀请有奖", @"公告", @"计算器", @"帮助中心"];
//    NSArray *fwItemImages = @[@"youhuiquan", @"shoucang", @"zuji", @"dizhi", @"hangqing", @"notification", @"bangzhu", @"zhengshu", @"jisuanqi", @"factoryAddress"];
//    NSArray *fwItemTitles = @[@"优惠券", @"收藏", @"足迹", @"管理地址", @"实时金价", @"公告", @"帮助中心", @"证书查询", @"计算器", @"工厂地址"];
    
    NSArray *fwItemImages = @[@"youhuiquan", @"shoucang", @"dizhi", @"hangqing", @"notification", @"bangzhu", @"zhengshu", @"jisuanqi"];
    NSArray *fwItemTitles = @[@"优惠券", @"收藏", @"管理地址", @"实时金价", @"公告", @"帮助中心", @"证书查询", @"计算器"];
    NSMutableArray *fuwuArray = [NSMutableArray array];
    for (int i = 0; i < fwItemImages.count; i++) {
        NSString *itemTitle = fwItemTitles[i];
        TTMineItemModel *model = [TTMineItemModel setImageName:fwItemImages[i] title:itemTitle];
        [fuwuArray addObject:model];
    }
    TTMineViewModel *model2 = [TTMineViewModel setModelWithSectionTitle:myServiceTitle itemArray:fuwuArray];
    model2.corner = UIRectCornerAllCorners;
    [self.dataArray addObject:model2];
    
    
//    NSArray *ddItemImages = @[@"daiqueren", @"chulizhong", @"daifahuo", @"yifahuo", @"daijiesuan"];
//    NSArray *ddItemTitles = @[@"待确认", @"处理中", @"待发货", @"已发货", @"待结算"];
//    NSMutableArray *dingdanArray = [NSMutableArray array];
//    for (int i = 0; i < ddItemImages.count; i++) {
//        TTMineItemModel *model = [TTMineItemModel setImageName:ddItemImages[i] title:ddItemTitles[i]];
//        [dingdanArray addObject:model];
//    }
//    TTMineViewModel *model = [TTMineViewModel setModelWithSectionTitle:myOrderTitle btnTitle:@"全部订单" target:self action:@selector(lookAllOrder) itemArray:dingdanArray];
//
//    [self.dataArray addObject:model];
    
    [self.tableView reloadData];
    
    
}

///获取缓存的海报数据
- (NSArray *)getCachePosterDatas
{
    if (self.posterUseKey == nil) {
        return nil;
    }
    
    return [USER_DEFAULT objectForKey:self.posterUseKey];
}

///保存海报
- (void)savePosterDatas:(NSArray *)array
{
    if (self.posterUseKey == nil) {
        return;
    }
    [USER_DEFAULT setObject:array forKey:self.posterUseKey];
}
///获取海报的key
- (NSString *)posterUseKey
{
    if ([TTLoginSingle sharedSingle].loginModel.Mobile.length == 0) {
        _posterUseKey = nil;
    } else {
        _posterUseKey = [NSString stringWithFormat:@"%@_%@", [TTLoginSingle sharedSingle].loginModel.Mobile, posterKey];
    }
    return _posterUseKey;
}


- (void)setupSubviews
{
    self.headerView = [[TTMineHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, topImageViewH - 64)];
    self.tableView.tableHeaderView = self.headerView;
    @weakify(self)
    self.headerView.clickSFZBlock = ^{
        @strongify(self)
        if ([TTLoginSingle sharedSingle].userModel.VipLevel == 1) {
            [self presentDianpuViewController];
        }
    };
    
    UIImage *topBgImage = [UIImage imageNamed:@"mine__top_bg"];
    self.headerBGImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -kStatusBarHeight - topImageViewH * 0.5, self.view.width, topImageViewH )];
    //    _topBgImageView.contentMode = UIViewContentModeScaleAspectFit;
    self.headerBGImageView.image = topBgImage;
    self.headerBGImageView.layer.anchorPoint = CGPointMake(0.5, 0);
    [self.view insertSubview:self.headerBGImageView belowSubview:self.tableView];
    
    [self setupNavBarView];
    
    // 设置用户数据
    [self.headerView setUserData];
    
}

- (void)setupNavBarView
{
    if (_navAlphaView) return;
    
    _navAlphaView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, StatusBarAndNavBar_Height)];
    _navAlphaView.alpha = 0;
    _navAlphaView.backgroundColor = kMainColor;
    [self.view addSubview:_navAlphaView];
    
    _navBarView = [[UIView alloc] initWithFrame:_navAlphaView.frame];
    [self.view addSubview:_navBarView];
    
    UILabel *titleLabel = [UILabel labelWithTitle:@"我的" color:[UIColor whiteColor] font:[UIFont boldSystemFontOfSize:18]];
    [_navBarView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(kStatusBarHeight);
        make.centerX.equalTo(self.navBarView);
        make.height.mas_equalTo(44);
    }];
    
    UIButton *rightBtn = [UIButton createButtonWithImage:[UIImage imageNamed:@"shezhi"] target:self action:@selector(clickSetBtnAction)];
    rightBtn.contentMode = UIViewContentModeCenter;
    rightBtn.isNeedLogin = YES;
    [_navBarView addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).mas_offset(-10);
        make.top.equalTo(titleLabel);
        make.width.height.mas_equalTo(44);
    }];
    
    [_navBarView addSubview:self.activityView];
    [self.activityView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(titleLabel);
        make.right.equalTo(titleLabel.mas_left).mas_offset(-5);
    }];
    
}

- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([TTOpenPlusViewCell class]) bundle:nil] forCellReuseIdentifier:openPlusCellID];
        [_tableView registerClass:[TTMineViewCell class] forCellReuseIdentifier:cellID];
        [_tableView registerClass:[TTMineBigPosterViewCell class] forCellReuseIdentifier:posterCellID];
        _tableView.tableFooterView = [UIView new];
        [self.view addSubview:_tableView];
        
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.mas_topLayoutGuideTop).mas_offset(-kStatusBarHeight);
            make.left.right.equalTo(self.view);
            make.bottom.equalTo(self.mas_bottomLayoutGuideBottom);
        }];
    }
    return _tableView;
}



- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

- (UIActivityIndicatorView *)activityView
{
    if (!_activityView) {
        _activityView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(self.view.width * 0.5 - 45, 0, 20, 44)];
        _activityView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
        [self.navigationController.navigationBar addSubview:_activityView];
    }
    return _activityView;
}

- (void)dealloc
{
    NSLog(@"[< %@ >] --> 释放了", self.className);
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
